import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import WeuiVue from 'weui-design-vue'

import './assets/css/reset.css'
import './assets/css/common.css'
// import './style/variable.scss'
import 'weui-design-vue/lib/weui-design-vue.css'

import Dialog from './components/dialog'
import Loading from './components/loading'
import toast from './components/toast'

import './JS/plugin'
import { get, post } from './JS/ajax'
import utils from './JS/utils'
import FastClick from 'fastclick'

if ('addEventListener' in document) {
  document.addEventListener('DOMContentLoaded', () => {
    FastClick.attach(document.body)
  }, false)
}
FastClick.prototype.focus = function (targetElement) {
  targetElement.focus()
}

Vue.config.productionTip = false

Vue.use(utils)
Vue.use(WeuiVue)

Vue.prototype.$dialog = Dialog
Vue.prototype.$loading = Loading
Vue.prototype.$toast = toast
Vue.prototype.$http = { get, post }

router.beforeEach((to, from, next) => {
  document.title = to.meta.title
  const userInfo = sessionStorage.getItem('userInfo') || null
  if (!userInfo && to.meta.auth) {
    next('/login')
  } else {
    next()
  }
})

export default new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
